function a(a, t, e) {
    return t in a ? Object.defineProperty(a, t, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : a[t] = e, a;
}

var t, e = require("../../utils/api.js"), o = getApp();

Page((t = {
    data: {
        checkAll: !0,
        totalCount: 0,
        totalPrice: "0.00",
        totalId: [],
        del_id: "",
        delStatus: !0,
        goods: [],
        none: "none",
        min: 1,
        footer: [],
        carnum: wx.getStorageSync("cartnum"),
        showLoding: !0,
        showSuccesstipInfo: {
            showSuccesstip: !0,
            title: "删除成功",
            type: !0
        },
        firstJump: void 0,
        enjoyFullReduce: !1,
        showBar: !0,
        default_small_img: o.globalData.default_small_img,
        inputfocus: 0
    },
    onLoad: function(a) {
        var t = this;
        t.setData({
            showLoding: !1
        });
        var n = e.getfooter();
        wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        }), e.getCart({
            openid: wx.getStorageSync("openid")
        }).then(function(a) {
            console.log(a);
            for (var e = [], o = 0; o < a.data.length; o++) a.data[o].title = a.data[o].g_name, 
            a.data[o].id = a.data[o].c_g_id, a.data[o].cover = a.data[o].g_icon, 1 == a.data[o].g_has_option ? a.data[o].group = a.data[o].ggo_market_price : a.data[o].group = a.data[o].g_price, 
            a.data[o].retail = a.data[o].g_old_price, a.data[o].count = parseInt(a.data[o].c_count), 
            a.data[o].weighing = a.data[o].g_brief, a.data[o].checked = !0, e.push(a.data[o]);
            wx.setStorage({
                key: "cart_goods",
                data: e
            }), t.setData({
                goodList: e,
                carnum: wx.getStorageSync("cartnum"),
                none: "block",
                footer: n,
                showBar: !1
            });
        });
        for (var d = getCurrentPages(), i = "/" + d[d.length - 1].route, s = 0; s < t.data.footer.length; s++) i == t.data.footer[s].url && (t.data.footer[s].nav = 2);
        t.setData({
            footer: t.data.footer
        }), 0 == o.globalData.is_open_full_reduction && t.setData({
            disPrice: -1
        });
    },
    tel: function(a) {
        var t = a.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber: t
        });
    },
    onShow: function(a) {
        var t = this;
        e.getCartNum({
            openid: o.globalData.openid
        }).then(function(a) {
            console.log(a), wx.setStorageSync("cartnum", a.data), t.setData({
                carnum: a.data
            });
        }), e.getCart({
            openid: wx.getStorageSync("openid")
        }).then(function(a) {
            for (var e = [], n = 0; n < a.data.length; n++) a.data[n].title = a.data[n].g_name, 
            a.data[n].id = a.data[n].c_g_id, a.data[n].cover = a.data[n].g_icon, 1 == a.data[n].g_has_option ? a.data[n].group = a.data[n].ggo_market_price : a.data[n].group = a.data[n].g_price, 
            a.data[n].retail = a.data[n].g_old_price, a.data[n].count = parseInt(a.data[n].c_count), 
            a.data[n].weighing = a.data[n].g_brief, a.data[n].checked = !0, e.push(a.data[n]);
            wx.setStorage({
                key: "cart_goods",
                data: e
            }), t.setData({
                goodList: e,
                carnum: wx.getStorageSync("cartnum"),
                checkAll: !0,
                totalCount: 0,
                totalPrice: "0.00",
                totalPrices: "0.00",
                discount: 0,
                showLoding: !0,
                firstJump: !0,
                full_reduction_price: parseFloat(o.globalData.full_reduction_price),
                full_reduction_limit_price: parseFloat(o.globalData.full_reduction_limit_price),
                is_open_full_reduction: o.globalData.is_open_full_reduction
            });
            for (var d = 0, n = 0; n < e.length; n++) 1 == e[n].g_is_full_reduce && 1 == t.data.is_open_full_reduction && (d = parseInt(d) + 1);
            t.setData({
                fullReduceNum: d
            }), 0 != a.data.length ? (wx.showTabBarRedDot({
                index: 2
            }), wx.setTabBarBadge({
                index: 2,
                text: a.data.length + ""
            })) : wx.hideTabBarRedDot({
                index: 2
            }), t.calculateTotal();
        });
    },
    calculateTotal: function() {
        for (var a = this, t = a.data.goodList, e = 0, n = 0, d = 0, i = 0, s = 0; s < t.length; s++) {
            var l = t[s];
            l.checked && (e += parseInt(l.count), n += parseInt(l.count) * l.group, d += parseInt(l.count) * l.g_old_price, 
            1 == l.g_is_full_reduce && (i += parseFloat(l.group) * parseFloat(l.count)));
        }
        if (1 == a.data.is_open_full_reduction) {
            var r = parseFloat(o.globalData.full_reduction_limit_price) - i;
            r > 0 ? a.setData({
                disPrice: parseFloat(r).toFixed(2),
                enjoyFullReduce: !1
            }) : a.setData({
                enjoyFullReduce: !0,
                disPrice: -1
            });
        }
        n = n.toFixed(2);
        var c = (d = d.toFixed(2)) - n;
        c = c.toFixed(2), a.setData({
            totalCount: e,
            totalPrice: n,
            totalPrices: d,
            discount: c
        });
    },
    checkboxChange: function(a) {
        for (var t = this, e = t.data.goodList, o = Array(), n = Array(), d = 0; d < a.detail.value.length; d++) {
            var i = a.detail.value[d].split(",");
            o[d] = i[0], n[d] = i[1];
        }
        t.setData({
            totalId: o,
            gid: n
        });
        for (var s = [], d = 0; d < e.length; ++d) {
            e[d].checked = !1;
            for (var l = null, r = 0; r < o.length; ++r) if (e[d].c_id == o[r]) {
                e[d].checked = !0, l = {
                    id: e[d].c_id,
                    num: e[d].count
                }, s.push(l);
                break;
            }
        }
        for (var c = [], u = wx.getStorageSync("coupon_id"), d = 0; d < u.length; ++d) for (var g = null, r = 0; r < s.length; ++r) u[d].id == s[r].id && (g = {
            id: s[r].id,
            num: s[r].num,
            gcg_id: u[r].gcg_id
        }, c.push(g));
        var p = !1;
        e.length == o.length && (p = !0), this.setData({
            goodList: e,
            checkAll: p
        }), t.calculateTotal(), t.setData({
            goods: a.detail.value
        });
    },
    selectalltap: function(a) {
        console.log("用户点击全选，携带value值为：", a.detail.value);
        var t = this, e = a.detail.value, o = !1, n = t.data.goodList;
        if (console.log(e[0]), e && e[0]) {
            o = !0;
            for (var d = [], i = 0; i < n.length; i++) {
                var s = {
                    id: n[i].c_id,
                    num: n[i].count
                };
                d.push(s);
            }
            for (var l = [], r = wx.getStorageSync("coupon_id"), i = 0; i < r.length; ++i) for (var c = null, u = 0; u < d.length; ++u) r[i].id == d[u].id && (c = {
                id: d[u].c_id,
                num: d[u].num,
                gcg_id: r[u].gcg_id
            }, l.push(c));
            t.setData({
                goods: l
            });
        } else t.setData({
            goods: []
        });
        for (i = 0; i < n.length; i++) n[i].checked = o;
        t.setData({
            checkAll: o,
            goodList: n
        }), t.calculateTotal();
    },
    onChange: function(a) {
        var t = this;
        if (console.log(a), console.log(t.data.inputfocus), 1 == t.data.inputfocus) return !1;
        console.log(t.data.goodList);
        var n = a.currentTarget.dataset.id, d = a.currentTarget.dataset.cid, i = a.currentTarget.dataset.old, s = a.currentTarget.dataset.stock, l = a.currentTarget.dataset.limit, r = Math.min(s, l);
        if (s = parseInt(s), l = parseInt(l), console.log(s, l, r, i), a.detail.detail && a.detail.detail.value && parseFloat(a.detail.detail.value) > 0) c = parseInt(a.detail.detail.value); else if (a.detail.detail && "" == a.detail.detail.value || a.detail.detail && parseFloat(a.detail.detail.value) <= 0) {
            wx.showToast({
                title: "商品数量要大于0哦",
                icon: "none",
                duration: 2e3
            });
            c = parseInt(i);
        } else if (a.detail.detail) c = parseInt(i); else c = a.detail;
        if (console.log(c, r), c <= r && l > 0) ; else if (c <= parseInt(s) && 0 == l) ; else if (c > parseInt(s)) {
            wx.showToast({
                title: "商品数量没有那么多了",
                icon: "none",
                duration: 2e3
            });
            c = parseInt(i);
        } else if (c > parseInt(l)) {
            wx.showToast({
                title: "商品限购" + l + "件哦",
                icon: "none",
                duration: 2e3
            });
            var c = parseInt(i);
        }
        console.log(n, d, i, c);
        if (i < parseInt(c)) u = "up"; else var u = "down";
        console.log(d, c, o.globalData.openid), t.setData({
            showLoding: !1
        }), e.savecart({
            id: d,
            num: parseInt(c),
            act: u,
            openid: o.globalData.openid
        }).then(function(a) {
            console.log(a), wx.hideLoading();
            var e = t.data.goodList;
            if (1 == a.errno) ; else {
                for (var o = 0; o < e.length; o++) e[o].c_id == n && (e[o].count = c);
                t.setData({
                    carnum: a.data
                }), console.log(a.data), wx.setStorageSync("cartnum", a.data);
            }
            t.setData({
                goodList: e,
                showLoding: !0
            }), t.calculateTotal();
        });
    },
    overlimit: function(a) {
        console.log(a);
        var t = this, e = t.data.cur_cid;
        console.log(e), void 0 == e && wx.showToast({
            title: "超出可购买数量了",
            icon: "none",
            duration: 2e3
        }), t.setData({
            delStatus: !this.data.delStatus,
            del_id: e
        });
    },
    onblur: function(a) {
        console.log(a), this.setData({
            inputfocus: 0
        }), this.onChange(a), console.log(this.data.inputfocus);
    },
    onfocus: function() {
        this.setData({
            inputfocus: 1
        }), console.log(this.data.inputfocus);
    }
}, a(t, "overlimit", function(a) {
    var t = this, e = a.currentTarget.dataset.cid;
    console.log(a), t.setData({
        delStatus: !this.data.delStatus,
        del_id: e,
        goodsIndex: a.currentTarget.dataset.index
    });
}), a(t, "delgoods", function() {
    var a = this;
    a.setData({
        showLoding: !1
    });
    var t = [], n = a.data.goodsIndex, d = a.data.fullReduceNum, i = a.data.goodList, s = 0;
    console.log(i);
    for (var l = 0; l < i.length; l++) 1 == i[l].checked && (t.push(i[l].c_id), 1 == i[l].g_is_full_reduce && (s += 1));
    console.log(t, s);
    var r = {
        ids: t,
        openid: o.globalData.openid
    };
    e.cartGoodsDel(r).then(function(t) {
        console.log(t), 0 == t.errno ? (a.setData({
            carnum: t.data
        }), wx.setStorageSync("cartnum", parseInt(t.data))) : a.successtip("删除失败", !1), 
        setTimeout(function() {
            0 == t.errno && e.getCart({
                openid: wx.getStorageSync("openid")
            }).then(function(t) {
                console.log(t);
                for (var e = [], o = 0; o < t.data.length; o++) t.data[o].title = t.data[o].g_name, 
                t.data[o].id = t.data[o].c_g_id, t.data[o].cover = t.data[o].g_icon, t.data[o].group = 0 == t.data[o].g_has_option ? t.data[o].g_price : t.data[o].ggo_market_price, 
                t.data[o].retail = 0 == t.data[o].g_has_option ? t.data[o].g_old_price : t.data[o].ggo_old_price, 
                t.data[o].count = parseInt(t.data[o].c_count), t.data[o].weighing = t.data[o].g_brief, 
                t.data[o].checked = !0, e.push(t.data[o]);
                a.setData({
                    goodList: e,
                    showLoding: !0,
                    checkAll: !0
                }), a.successtip("已移除购物车"), a.calculateTotal(), 0 != e.length ? (wx.showTabBarRedDot({
                    index: 2
                }), wx.setTabBarBadge({
                    index: 2,
                    text: t.data.length + ""
                })) : wx.hideTabBarRedDot({
                    index: 2
                });
            }), n <= d - s && a.setData({
                fullReduceNum: d - s
            });
        }, 1e3);
    });
}), a(t, "modalChange", function() {
    var a = this;
    a.setData({
        showLoding: !1
    });
    var t = a.data.goodsIndex, n = a.data.fullReduceNum, d = {
        id: a.data.del_id,
        openid: wx.getStorageSync("openid") ? wx.getStorageSync("openid") : o.globalData.openid
    };
    e.cartGoodsDel(d).then(function(o) {
        0 == o.errno ? (console.log(o), a.setData({
            carnum: o.data
        }), wx.setStorageSync("cartnum", parseInt(o.data))) : a.successtip("删除失败", !1), 
        setTimeout(function() {
            0 == o.errno && e.getCart({
                openid: wx.getStorageSync("openid")
            }).then(function(t) {
                for (var e = [], o = 0; o < t.data.length; o++) t.data[o].title = t.data[o].g_name, 
                t.data[o].id = t.data[o].c_g_id, t.data[o].cover = t.data[o].g_icon, t.data[o].group = 0 == t.data[o].g_has_option ? t.data[o].g_price : t.data[o].ggo_market_price, 
                t.data[o].retail = 0 == t.data[o].g_has_option ? t.data[o].g_old_price : t.data[o].ggo_old_price, 
                t.data[o].count = parseInt(t.data[o].c_count), t.data[o].weighing = t.data[o].g_brief, 
                t.data[o].checked = !0, e.push(t.data[o]);
                a.setData({
                    goodList: e,
                    showLoding: !0
                }), a.successtip("已移除购物车"), a.calculateTotal(), 0 != e.length ? (wx.showTabBarRedDot({
                    index: 2
                }), wx.setTabBarBadge({
                    index: 2,
                    text: t.data.length + ""
                })) : wx.hideTabBarRedDot({
                    index: 2
                });
            }), t <= n - 1 && a.setData({
                fullReduceNum: n - 1
            });
        }, 1e3);
    }), a.setData({
        delStatus: !a.data.delStatusb
    }), a.onLoad;
}), a(t, "modalCancel", function() {
    this.setData({
        delStatus: !this.data.delStatus
    });
}), a(t, "accounts", function() {
    var a = this;
    if (1 == o.globalData.is_first_enter) {
        var t = "back";
        return t = encodeURIComponent(t), wx.navigateTo({
            url: "/pages/authorization/authorization?url=" + t
        }), !1;
    }
    if (a.data.firstJump) {
        a.data.totalId, a.data.goodList;
        if (a.data.totalCount < 1) return wx.showModal({
            title: "提示",
            content: "请选择你要购买的商品",
            showCancel: !1,
            success: function(a) {}
        }), !1;
        var e = {
            goods: a.data.goods,
            totalPrice: a.data.totalPrice
        };
        wx.setStorage({
            key: "cart",
            data: e
        }), a.data.checkAll ? wx.navigateTo({
            url: "../checkout/carCheckout?checkAll=true",
            success: function() {
                a.setData({
                    firstJump: !1
                });
            }
        }) : wx.navigateTo({
            url: "../checkout/carCheckout"
        });
    }
}), a(t, "sites", function(a) {
    var t = this, e = a.currentTarget.dataset.data_index, o = t.data.footer, n = [ "/pages/template/index", "/pages/template/classify", "/pages/template/cart", "/pages/personal/personal" ];
    "url" == o.params.data[e].type ? n.includes(o.params.data[e].url) ? wx.reLaunch({
        url: o.params.data[e].url,
        success: function() {
            t.setData({
                showLoding: !0
            });
        }
    }) : wx.navigateTo({
        url: o.params.data[e].url,
        success: function() {
            t.setData({
                showLoding: !0
            });
        }
    }) : "tel" == o.params.data[e].type ? wx.makePhoneCall({
        phoneNumber: o.params.data[e].url
    }) : "out_link" == o.params.data[e].type ? wx.navigateTo({
        url: "/pages/template/out_h5?url=" + o.params.data[e].url
    }) : "app" == o.params.data[e].type && wx.navigateToMiniProgram({
        appId: o.params.data[e].url_name,
        path: o.params.data[e].url,
        envVersion: "develop",
        success: function(a) {}
    });
}), a(t, "stopscorll", function() {}), a(t, "successtip", function() {
    var t, e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "", o = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "true", o = "showSuccesstipInfo.type", n = this;
    n.setData((t = {}, a(t, "showSuccesstipInfo.showSuccesstip", !n.data.showSuccesstipInfo.showSuccesstip), 
    a(t, "showSuccesstipInfo.title", e), a(t, o, o), t)), setTimeout(function() {
        var t;
        n.setData((t = {}, a(t, "showSuccesstipInfo.showSuccesstip", !n.data.showSuccesstipInfo.showSuccesstip), 
        a(t, "showSuccesstipInfo.title", e), a(t, o, o), t));
    }, 1300);
}), a(t, "buymore", function() {
    wx.redirectTo({
        url: "/pages/template/index"
    });
}), t));